<?php
/**
 * Created by PhpStorm.
 * User: 小蛮哼哼哼
 * Email: 243194993@qq.com
 * Date: 2021/11/29
 * Time: 14:27
 * motto: 现在的努力是为了小时候吹过的牛逼！
 */

declare(strict_types=1);

namespace app\api\controller\v1;

use app\api\controller\Base;
use app\common\business\Collection as BusObj;
use app\common\lib\Show;
use app\common\lib\Status;
use think\App;
use const Grpc\STATUS_ABORTED;

class Collection extends Base
{
    protected BusObj $busObj;

    public function __construct(App $app)
    {
        $this->busObj = new BusObj();
        parent::__construct($app);
    }

    /**
     * @return \think\response\Json
     */
    public function setCollection()
    {
        $id = $this->request->param('id', 0, 'intval');
        if ($id == 0) {
            return Show::json_show(Status::mini_error, "操作失败");
        }
        $openid = $this->request->param('openid', '', 'trim');

        try {
            $res = $this->busObj->setCollection($id, $openid);
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        if ($res) {
            return Show::json_show(Status::mini_normal, $res);
        } else {
            return Show::json_show(Status::mini_error, "操作失败");
        }
    }

    public function getCollectionByList()
    {
        $openid = $this->request->param('openid', '', 'trim');
        if (empty($openid)) {
            return Show::json_show(Status::mini_error, "系统错误");
        }
        try {
            $collection = $this->busObj->getCollectionByList($openid, '*,theatre_id as get_theatre_data,create_time as big_time');
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        return Show::json_show(Status::mini_normal, "ok", $collection);
    }

    public function getCollection()
    {
        $id = $this->request->param('id', 0, 'intval');
        if ($id == 0) {
            return Show::json_show(Status::mini_error, "系统错误");
        }
        try {
            $order = $this->busObj->getCollection($id);
        } catch (\Exception $e) {
            return Show::json_show(Status::mini_error, $e->getMessage());
        }
        return Show::json_show(Status::mini_normal, 'ok');
    }

}